package cn.stylefeng.guns.modular.hx.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.storage.entity.HxStorageCenter;
import cn.stylefeng.guns.modular.hx.storage.mapper.HxStorageCenterMapper;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxStorageCenterParam;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxStorageOutParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxStorageCenterResult;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxStorageOutResult;
import  cn.stylefeng.guns.modular.hx.storage.service.HxStorageCenterService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 备货区分配 服务实现类
 * </p>
 *
 * @author lww
 * @since 2023-10-23
 */
@Service
public class HxStorageCenterServiceImpl extends ServiceImpl<HxStorageCenterMapper, HxStorageCenter> implements HxStorageCenterService {

    @Override
    public void add(HxStorageCenterParam param){
        HxStorageCenter entity = getEntity(param);
        this.save(entity);
    }

// 查门店
    @Override
    public List<HxStorageOutResult> findGetunit(HxStorageOutParam param) {
        return baseMapper.storageunit(param);
    }
// 分配门店给备货库
    @Override
    public int insert(HxStorageCenterParam param) {
        return baseMapper.insert(param);
    }

    @Override
    public void delete(HxStorageCenterParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxStorageCenterParam param){
        HxStorageCenter oldEntity = getOldEntity(param);
        HxStorageCenter newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HxStorageCenterResult findBySpec(HxStorageCenterParam param){
        return null;
    }

    @Override
    public List<HxStorageCenterResult> findListBySpec(HxStorageCenterParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxStorageCenterParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findHxStorageOutFenpeiBySpec(HxStorageOutParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findHxStorageOutFenpeiBySpec(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HxStorageCenterParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxStorageCenter getOldEntity(HxStorageCenterParam param) {
        return this.getById(getKey(param));
    }

    private HxStorageCenter getEntity(HxStorageCenterParam param) {
        HxStorageCenter entity = new HxStorageCenter();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public void updateBySpec(HxStorageCenterParam hxStorageCenterParam) {
		this.baseMapper.updateBySpec(hxStorageCenterParam);
	}

    @Override
    public void insertStockPort(HxStorageCenterParam hxStorageCenterParam) {
        this.baseMapper.insertStockPort(hxStorageCenterParam);
    }

    @Override
    public int clearall(HxStorageCenterParam hxStorageCenterParam) {
        int clearall = this.baseMapper.clearall(hxStorageCenterParam);
        return clearall;
    }

}
